﻿@model IEnumerable<ETL.Business.Models.ProjectTaskModel>
@{
    ViewBag.Title = "Engineer Time Logging";
}
<script type="text/javascript">

    $(document).ready(function () {

        // Hide task id column which is needed for ajax request
//        $('#ajaxGridTask thead tr th:first').css('display', 'none');
//        $('#ajaxGridTask tbody tr').each(
//            function () {
//                $('td:first', this).css('display', 'none');
//            }
//        );
    });

    $(function () {

        // Highlight hovered row
        //        $('#ajaxGridTask tbody tr').live('mouseover', function () {
        //            $(this).addClass('clickable');
        //        });
        //        $('#ajaxGridTask tbody tr').live('mouseleave', function () {
        //            $(this).removeClass('clickable');
        //        });

        // Ajax request when a row is clicked
        $('#ajaxGridTask tbody tr').click(function () {

            
            // highlight selected row
            $('#ajaxGridTask tbody tr').each(
                function () {
                    $(this).removeClass('selected');
                }
            );
            $(this).addClass('selected');

            // Get task id
            var currentTaskId = $(this).find('td:first').text();

            var r = confirm("Do you want to logon to this task ?");
            if (r == true) {
                //enable free entry button
                $("#btnFreeEntry").removeAttr("disabled");
                $("#btnFreeEntry").unbind("click");
                $("#btnFreeEntryAdmin").removeAttr("disabled");
                $("#btnFreeEntryAdmin").unbind("click");

                // Ajax function
                $.ajax({
                    url: "/EnTimeLog/LogOnToATask",
                    type: 'POST',
                    data: {
                        TaskId: currentTaskId
                    },
                    success: function (response) {
                        // disable the button
                        $("#btnResumePreviousTask").attr("disabled", "disabled");

                        alert(response);


                    },
                    error: function (xhr) {
                        alert("Error!");
                    }
                });
            }
            else {
                // disable free entry button
                $("#btnFreeEntry").attr("disabled", "disabled");

            }
        });
    });
</script>
@{
    var gridTask = new WebGrid(
        Model,
        defaultSort: "Name",
        fieldNamePrefix: "gridTask_",
        canSort : false,
        canPage : false
        );
}
<div id="ajaxGridTask" >
    <div class="well">
    @if (Model != null && Model.Count() > 0)
    {
        @gridTask.GetHtml(
            tableStyle: "table table-hover",
            //headerStyle: "webgrid-header",
            //footerStyle: "webgrid-footer",
            //alternatingRowStyle: "webgrid-alternating-row",
            //selectedRowStyle: "webgrid-selected-row",
            //rowStyle: "webgrid-row-style",
            columns: gridTask.Columns(
                gridTask.Column("Task Id", null, @<text>@item.TaskId</text>),
                gridTask.Column("Task", "Task", @<text>@item.TaskName</text>),
                gridTask.Column("Project", "Project", @<text>@item.ProjectName</text>),
                gridTask.Column("Project ID", "ProjectId", @<text>@item.ProjectId</text>)
                )
            )
    }
    </div>
</div>
